<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";

import { exchangeRecord, exchangeStatus } from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "未兑换", value: "1" },
        { label: "已兑换", value: "2" },
      ],
      queryData: {
        dh_status: "",
        sign_number: "",
        goods_name: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    checkFn(row, type) {
      let str =
        type == 2
          ? "确定将选择的兑奖记录状态更改为已兑奖吗?请输入兑换备注"
          : "确定驳回此项商品兑换申请吗？确认驳回状态将改为已驳回";
      ElMessageBox.prompt(str, "操作提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then((value) => {
        let data = {
          user_integral_goods_sign_id: row.user_integral_goods_sign_id,
          status: type,
          dh_remark: value.value,
        };
        exchangeStatus(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    getData() {
      exchangeRecord(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  created() {
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>积分商品兑换记录（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.sign_number"
                placeholder="请输入兑奖单号"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.goods_name"
                placeholder="请输入商品名称"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.dh_status"
                clearable
                @change="getData"
                placeholder="请选择兑换状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="sign_number"
          width="180"
          show-overflow-tooltip
          label="兑奖单号"
        />
        <el-table-column
          prop="goods_name"
          show-overflow-tooltip
          width="150"
          label="兑换商品"
        />
        <el-table-column
          prop="user_name"
          show-overflow-tooltip
          label="兑奖用户"
        />
        <el-table-column
          prop="user_phone"
          show-overflow-tooltip
          width="150"
          label="手机号"
        />

        <el-table-column width="100" show-overflow-tooltip label="兑换状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.dh_status == 1">未兑换</el-tag>
              <el-tag type="success" v-if="row.dh_status == 2">已兑换</el-tag>
              <el-tag type="danger" v-if="row.dh_status == 3">已驳回</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="dh_time"
          width="180"
          show-overflow-tooltip
          label="兑换时间"
        />
        <el-table-column
          prop="create_time"
          width="180"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column
          prop="dh_remark"
          show-overflow-tooltip
          label="兑奖备注"
        />
        <el-table-column prop="Name" width="100" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="blueText ctrlText"
                v-if="row.dh_status == 1"
                @click="checkFn(row, 2)"
              >
                兑奖
              </div>
              <div
                class="redText ctrlText"
                v-if="row.dh_status == 1"
                @click="checkFn(row, 3)"
              >
                驳回
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
